<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<?php
session_start();
if (empty($_SESSION["loginusername"])) {
                                Header("Location: firstphp.php");
                            }
if (!empty($_SESSION["userType"])) {
    $userType = $_SESSION["userType"];
}
if($userType=="Therapy Assistant")
{
    header("Location: javascript://history.go(-1)");
}
?>
<html>
    <head>
        <title>Back Date</title>
        <link rel="stylesheet" href="http://localhost/Eldercare/jquery/style.css" type="text/css" media="screen"/>
        <link rel="stylesheet" href="http://localhost/Eldercare/jquery/jquery-ui.css" />
        <script src="http://localhost/Eldercare/jquery/jquery-1.9.1.js"></script>
        <script src="http://localhost/Eldercare/jquery/jquery-ui.js"></script>

        <link href="http://localhost/Eldercare/finalstyle.css" rel="stylesheet" type="text/css" media="all" />
        <script>
            /*var url;
             $(function() {
             $( "#datepicker" ).datepicker();
             });*/

            // $(function checkAttendanceRecord(){
            // $.get('BackDate/checkAttendanceRecord.php',{},function(data){
            //$('#tblAttendance').replaceWith($(data));  
            //  });
            //});


        </script>
    </head>
    <style type="text/css">
        body {
            background: #FFFFFF url("images/bg.png") repeat;
            background-attachment:fixed;
        }
        .button 
        {
            background-color:beige;
            cursor:pointer; }

        .btn
        {
            background-color:#FFF5EE;
            cursor:pointer;
        }
    </style>

    <body onLoad="document.formnric.barcode.focus();">                                                                                                                         <ul>
            <div class="banner"></div>
            <div id="main">
                <div class="left-wrapper">
                    <div class="logo">
                    </div>
                    <div class="menu-wrapper">
                        <div id='cssmenu' >     
                            <ul>                                                                                                                               
                                <?php
                                if ($userType == "Therapy Assistant") {
                                    //if TA
                                    echo "<li class='has-sub' class='active'><a href='http://localhost/Eldercare/AttendanceHome.php'><span>Attendance</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/AttendanceHome.php'><span>Attendance Taking</span></a></li>
			 <li class='last'><a href='http://localhost/Eldercare/ViewAttendanceRecord.php'><span>View Attendance</span></a></li>
			 </ul>
			  </li>
			  <li class='has-sub'><a href='#'><span>Profile</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/Client.php'><span>Existing Client</span></a></li>
         <li class='last'><a href='http://localhost/Eldercare/WClient.php'><span>Withdrawn Client</span></a></li>
      </ul>
   </li>
   <li class='has-sub'><a href='http://localhost/Eldercare/ActRecords.php'><span>Activities</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/ActRecords.php'><span>Activity Recording</span></a></li>
		 <li class='last'><a href='http://localhost/Eldercare/ViewActRecord.php'><span>View Activity Records</span></a></li>
      </ul>
   </li>
   <li class='has-sub'><a href='#'><span>Reports</span></a>
   <ul>
   <li><a href='http://localhost/Eldercare/Reports.php'><span>Attendance Reports</span></a></li>
   <li class='last'><a href='http://localhost/Eldercare/ActReports.php'><span>Activity Reports</span></a></li>
   </ul>
   </li>
   <li class='last'><a href='http://localhost/Eldercare/ManagePassword.php'><span>Change Passwords</span></a></li>
     
			 ";
                                } else if ($userType == "Centre Manager") {
                                    echo "
			<li class='has-sub' class='active'><a href='http://localhost/Eldercare/AttendanceHome.php'><span>Attendance</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/AttendanceHome.php'><span>Attendance Taking</span></a></li>
			 <li><a href='http://localhost/Eldercare/ViewAttendanceRecord.php'><span>View Attendance</span></a></li>
			<li><a href='http://localhost/Eldercare/BackDate.php'><span>BackDate</span></a></li>
			<li class='last'><a href='http://localhost/Eldercare/VerifyAttendance.php'><span>Verify Attendance</span></a></li>
			</ul>
			<li class='has-sub'><a href='#'><span>Profile</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/Client.php'><span>Existing Client</span></a></li>
         <li><a href='http://localhost/Eldercare/WClient.php'><span>Withdrawn Client</span></a></li>
         <li class='last'><a href='http://localhost/Eldercare/User.php'><span>User</span></a></li>
      </ul>
   </li>
   <li class='has-sub'><a href='http://localhost/Eldercare/ActRecords.php'><span>Activities</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/ActRecords.php'><span>Activity Recording</span></a></li>
         <li class='last'><a href='http://localhost/Eldercare/ViewActRecord.php'><span>View Activity Records</span></a></li>
      </ul>
   </li>
   <li class='has-sub'><a href='#'><span>Reports</span></a>
   <ul>
   <li><a href='http://localhost/Eldercare/Reports.php'><span>Attendance Reports</span></a></li>
   <li class='last'><a href='http://localhost/Eldercare/ActReports.php'><span>Activity Reports</span></a></li>
   </ul>
   </li>
    <li class='has-sub'><a href='#'><span>Password</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/ManagePassword.php'><span>Change Passwords</span></a></li>
         <li class='last'><a href='http://localhost/Eldercare/ForgetPasswords.php'><span>Forget Password</span></a></li>
      </ul>
   </li>
			";
                                } else {
                                    echo "
			<li class='has-sub' class='active'><a href='http://localhost/Eldercare/AttendanceHome.php'><span>Attendance</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/AttendanceHome.php'><span>Attendance Taking</span></a></li>
			 <li><a href='http://localhost/Eldercare/ViewAttendanceRecord.php'><span>View Attendance</span></a></li>
			<li><a href='http://localhost/Eldercare/BackDate.php'><span>BackDate</span></a></li>
			<li class='last'><a href='http://localhost/Eldercare/VerifyAttendance.php'><span>Verify Attendance</span></a></li>
			</ul>
			<li class='has-sub'><a href='#'><span>Profile</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/Client.php'><span>Existing Client</span></a></li>
         <li><a href='http://localhost/Eldercare/WClient.php'><span>Withdrawn Client</span></a></li>
         <li><a href='http://localhost/Eldercare/User.php'><span>User</span></a></li>
         <li class='last'><a href='http://localhost/Eldercare/Centres.php'><span>Centres</span></a></li>
      </ul>
   </li>
   <li class='has-sub'><a href='http://localhost/Eldercare/ActRecords.php'><span>Activities</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/Activities.php'><span>Manage Current Activities</span></a></li>
         <li><a href='http://localhost/Eldercare/ActRecords.php'><span>Activity Recording</span></a></li>
         <li class='last'><a href='http://localhost/Eldercare/ViewActRecord.php'><span>View Activity Records</span></a></li>
      </ul>
   </li>
   <li><a href='http://localhost/Eldercare/Holidays.php'><span>Holiday</span></a></li>
<li class='has-sub'><a href='#'><span>Reports</span></a>
   <ul>
   <li><a href='http://localhost/Eldercare/Reports.php'><span>Attendance Reports</span></a></li>
   <li class='last'><a href='http://localhost/Eldercare/ActReports.php'><span>Activity Reports</span></a></li>
   </ul>
   </li>
    <li class='has-sub'><a href='#'><span>Password</span></a>
      <ul>
         <li><a href='http://localhost/Eldercare/ManagePassword.php'><span>Change Passwords</span></a></li>
         <li class='last'><a href='http://localhost/Eldercare/ForgetPasswords.php'><span>Forget Password</span></a></li>
      </ul>
   </li>
			";
                                }
                                ?>
                            </ul>
                        </div>
                        <div class="clear"></div></div></div>
                <div class="content">
                    <div class="content2">
                        <b style="float:right; margin: 0px 0 0 0">  <?php
                            //session_start();
                            if (!empty($_SESSION["centreName"])) {
                                $Username = $_SESSION["loginusername"];
                                $centreName = $_SESSION["centreName"];
                                echo "Welcome, " . $Username . " ! <br>" . $centreName . " Branch";
                            } else {
                                $Username = $_SESSION["loginusername"];
                                echo "Welcome, " . $Username;
                            }
                            ?>
                            <?php
                            
                            ?>
                            <?php
//session_start();
// set timeout period in seconds
                            $inactive = 7200;
// check to see if $_SESSION['timeout'] is set
                            if (isset($_SESSION["timeout"])) {
                                $session_life = time() - $_SESSION["timeout"];
                                if ($session_life > $inactive) {
                                    session_destroy();
                                    Header("Location: Timeout.php");
                                }
                            }
                            $_SESSION["timeout"] = time();
                            ?>


                            <input type="submit" class="button" value="Logout" onclick="parent.location = 'logout.php';"></b>
                        </p><div class="clear"></div>
                        <h3 style="vertical-align:left;text-align:left;">BackDate</h3>


                        <td rowspan="3" style="vertical-align:middle;text-align:center;width:70%"></td>
                        <p> <b>Please select a date:</b> <form method = "post"> <input type="date" name="datepicker" value=<?php date('Y-m-d') ?> id="datepicker" /><input type="submit" button class="btn"id="submit" value ='Submit' name="BackDate"/></form></p>

                        <table  cellpadding="0" cellspacing="0" style="width: 100%; height: 100px;">
                            <tr>
                                <td style="width: 20%; height: 20%;">
                                    <?php
                                    echo"
				<p style='vertical-align:middle;text-align:center'><b>Scan NRIC: </b>
				<form  method='POST' name='formnric'>&nbsp;&nbsp;
				<input id='barcode'class='tb10'type='text' name='barcode' size='10' maxLength='9'/>
				<input id = 'selectedDate' class='tb10' type = 'hidden' name = 'selectedDate' value = '";
                                    echo isset($_POST['BackDate']) ? $_POST['datepicker'] : '';
                                    echo" /></form></p>";


                                    if (isset($_POST['barcode'])) {
                                        
                                    } else {
                                        echo "<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='red'>Please enter the NRIC!</font></p>";
                                    }

                                   
				
                                    ?>

                                </td>

                                <td rowspan="3" valign="top"align="center"style="width:100%"><p></p>
                                    <?php
                                if (isset($_POST['BackDate'])) {
                                    $date = $_POST['datepicker'];
                                    $_SESSION['selectedBackDate'] = $_POST['datepicker'];
                                    if ($date < date('Y-m-d')) {
                                        if (empty($centreName)) {
                                            include_once("BackDate/sugetbackdate.php");
                                        } else {
                                            include_once("BackDate/getbackdate.php");
                                        }
                                    } else {
                                        echo "<font color='red'> You can only BackDate the day before today!";
                                    }
                                } else {
                                    echo " <font color= 'red'> Please select a date! </font>";
                                }
                                if (isset($_POST['barcode'])) {
                                    if (strlen($_POST['barcode']) == 9) {
                                        if (empty($centreName)) {
                                            include_once("BackDate/sumakebackdate.php");
                                            $_POST['BackDate'] = $_POST['datepicker'] = $_POST['selectedDate'];
                                            echo "<p></p>";
                                            include_once("BackDate/sugetbackdate.php");
                                        } else {
                                            echo "<p></p>";
                                            include_once("BackDate/makebackdate.php");
                                            $_POST['BackDate'] = $_POST['datepicker'] = $_POST['selectedDate'];
                                            include_once("BackDate/getbackdate.php");
                                        }
                                    } else {
                                        echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color='red'>Invalid NRIC!</font>";
                                    }
                                }
                                    ?>
                                </td>
                            <tr>
                                <td style="vertical-align:middle;text-align:center; width:20%">
                                </td></tr>		<tr></tr>
                            <tr>
                                <td style="width:20%">
                            </tr>
                        </table>
                    </div><div class="clear"></div></div>
            </div>
            
    </body> 
</html>